{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install tensorflow\n",
    "!pip install modelscope"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from AliOffline_Seg_Obj import * \n",
    "from alioffline_utils_img import *\n",
    "from PIL import Image\n",
    "\n",
    "img = Image.open('./test/1.png')\n",
    "iamges = [pil2tensor(img)]\n",
    "seg = AliOffline_Seg_Obj()\n",
    "result = seg.sample(iamges,'transparent')\n",
    "tensor2pil(result[0][0]).show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install timm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from AliOffline_Ddcolor import * \n",
    "from alioffline_utils_img import *\n",
    "from PIL import Image\n",
    "\n",
    "img = Image.open('./test/1.png')\n",
    "iamges = [pil2tensor(img)]\n",
    "seg = AliOffline_Ddcolor()\n",
    "result = seg.sample(iamges)\n",
    "tensor2pil(result[0][0]).show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install librosa\n",
    "!pip install fairseq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from AliOffline_Face_Detection import * \n",
    "from alioffline_utils_img import *\n",
    "from PIL import Image\n",
    "\n",
    "img = Image.open('./test/1.png')\n",
    "iamges = [pil2tensor(img)]\n",
    "seg = AliOffline_Face_Detection()\n",
    "result = seg.sample(iamges)\n",
    "face_mask = tensor2pil(result[0][0])\n",
    "face_mask.save('./test/face.png')\n",
    "face_mask.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install scikit-image\n",
    "!pip install mmcv\n",
    "!pip install mmdet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from AliOffline_Face_Match import * \n",
    "from alioffline_utils_img import *\n",
    "from PIL import Image\n",
    "\n",
    "two = Image.open('./test/two.jpg')\n",
    "one = Image.open('./test/one.jpg')\n",
    "iamges = [pil2tensor(two)]\n",
    "iamge = pil2tensor(one)\n",
    "seg = AliOffline_Face_Match()\n",
    "result = seg.sample(iamges,iamge)\n",
    "face_mask = tensor2pil(result[0][0])\n",
    "face_mask.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://repo.huaweicloud.com/repository/pypi/simple\n",
      "Collecting opencv-python\n",
      "  Downloading https://repo.huaweicloud.com/repository/pypi/packages/ec/6c/fab8113424af5049f85717e8e527ca3773299a3c6b02506e66436e19874f/opencv_python-4.10.0.84-cp37-abi3-win_amd64.whl (38.8 MB)\n",
      "     ---------------------------------------- 0.0/38.8 MB ? eta -:--:--\n",
      "     ---------------------------------------- 0.2/38.8 MB 4.1 MB/s eta 0:00:10\n",
      "     ---------------------------------------- 0.3/38.8 MB 2.9 MB/s eta 0:00:14\n",
      "      --------------------------------------- 0.6/38.8 MB 4.1 MB/s eta 0:00:10\n",
      "      --------------------------------------- 0.9/38.8 MB 4.7 MB/s eta 0:00:09\n",
      "     - -------------------------------------- 1.1/38.8 MB 4.8 MB/s eta 0:00:08\n",
      "     - -------------------------------------- 1.4/38.8 MB 5.1 MB/s eta 0:00:08\n",
      "     - -------------------------------------- 1.6/38.8 MB 5.1 MB/s eta 0:00:08\n",
      "     - -------------------------------------- 1.9/38.8 MB 5.1 MB/s eta 0:00:08\n",
      "     -- ------------------------------------- 2.2/38.8 MB 5.2 MB/s eta 0:00:08\n",
      "     -- ------------------------------------- 2.5/38.8 MB 5.5 MB/s eta 0:00:07\n",
      "     -- ------------------------------------- 2.8/38.8 MB 5.5 MB/s eta 0:00:07\n",
      "     --- ------------------------------------ 3.1/38.8 MB 5.7 MB/s eta 0:00:07\n",
      "     --- ------------------------------------ 3.4/38.8 MB 5.6 MB/s eta 0:00:07\n",
      "     --- ------------------------------------ 3.7/38.8 MB 5.7 MB/s eta 0:00:07\n",
      "     ---- ----------------------------------- 4.0/38.8 MB 5.6 MB/s eta 0:00:07\n",
      "     ---- ----------------------------------- 4.3/38.8 MB 5.7 MB/s eta 0:00:07\n",
      "     ---- ----------------------------------- 4.6/38.8 MB 5.8 MB/s eta 0:00:06\n",
      "     ----- ---------------------------------- 4.9/38.8 MB 5.8 MB/s eta 0:00:06\n",
      "     ----- ---------------------------------- 5.1/38.8 MB 5.8 MB/s eta 0:00:06\n",
      "     ----- ---------------------------------- 5.5/38.8 MB 5.8 MB/s eta 0:00:06\n",
      "     ----- ---------------------------------- 5.8/38.8 MB 5.9 MB/s eta 0:00:06\n",
      "     ------ --------------------------------- 6.1/38.8 MB 5.9 MB/s eta 0:00:06\n",
      "     ------ --------------------------------- 6.4/38.8 MB 5.9 MB/s eta 0:00:06\n",
      "     ------ --------------------------------- 6.6/38.8 MB 5.9 MB/s eta 0:00:06\n",
      "     ------- -------------------------------- 7.0/38.8 MB 5.9 MB/s eta 0:00:06\n",
      "     ------- -------------------------------- 7.2/38.8 MB 5.9 MB/s eta 0:00:06\n",
      "     ------- -------------------------------- 7.5/38.8 MB 5.9 MB/s eta 0:00:06\n",
      "     -------- ------------------------------- 7.8/38.8 MB 6.0 MB/s eta 0:00:06\n",
      "     -------- ------------------------------- 8.1/38.8 MB 6.0 MB/s eta 0:00:06\n",
      "     -------- ------------------------------- 8.4/38.8 MB 5.9 MB/s eta 0:00:06\n",
      "     -------- ------------------------------- 8.7/38.8 MB 6.0 MB/s eta 0:00:06\n",
      "     --------- ------------------------------ 8.9/38.8 MB 6.0 MB/s eta 0:00:05\n",
      "     --------- ------------------------------ 9.2/38.8 MB 6.0 MB/s eta 0:00:05\n",
      "     --------- ------------------------------ 9.6/38.8 MB 6.0 MB/s eta 0:00:05\n",
      "     ---------- ----------------------------- 9.9/38.8 MB 6.0 MB/s eta 0:00:05\n",
      "     ---------- ----------------------------- 10.1/38.8 MB 6.0 MB/s eta 0:00:05\n",
      "     ---------- ----------------------------- 10.5/38.8 MB 6.1 MB/s eta 0:00:05\n",
      "     ----------- ---------------------------- 10.7/38.8 MB 6.2 MB/s eta 0:00:05\n",
      "     ----------- ---------------------------- 11.0/38.8 MB 6.2 MB/s eta 0:00:05\n",
      "     ----------- ---------------------------- 11.4/38.8 MB 6.2 MB/s eta 0:00:05\n",
      "     ------------ --------------------------- 11.7/38.8 MB 6.3 MB/s eta 0:00:05\n",
      "     ------------ --------------------------- 12.0/38.8 MB 6.3 MB/s eta 0:00:05\n",
      "     ------------ --------------------------- 12.2/38.8 MB 6.4 MB/s eta 0:00:05\n",
      "     ------------ --------------------------- 12.6/38.8 MB 6.4 MB/s eta 0:00:05\n",
      "     ------------- -------------------------- 12.9/38.8 MB 6.4 MB/s eta 0:00:05\n",
      "     ------------- -------------------------- 13.2/38.8 MB 6.4 MB/s eta 0:00:05\n",
      "     ------------- -------------------------- 13.6/38.8 MB 6.4 MB/s eta 0:00:04\n",
      "     -------------- ------------------------- 13.8/38.8 MB 6.4 MB/s eta 0:00:04\n",
      "     -------------- ------------------------- 14.2/38.8 MB 6.4 MB/s eta 0:00:04\n",
      "     -------------- ------------------------- 14.4/38.8 MB 6.4 MB/s eta 0:00:04\n",
      "     --------------- ------------------------ 14.7/38.8 MB 6.4 MB/s eta 0:00:04\n",
      "     --------------- ------------------------ 15.1/38.8 MB 6.4 MB/s eta 0:00:04\n",
      "     --------------- ------------------------ 15.3/38.8 MB 6.6 MB/s eta 0:00:04\n",
      "     ---------------- ----------------------- 15.7/38.8 MB 6.4 MB/s eta 0:00:04\n",
      "     ---------------- ----------------------- 16.0/38.8 MB 6.5 MB/s eta 0:00:04\n",
      "     ---------------- ----------------------- 16.3/38.8 MB 6.4 MB/s eta 0:00:04\n",
      "     ----------------- ---------------------- 16.6/38.8 MB 6.5 MB/s eta 0:00:04\n",
      "     ----------------- ---------------------- 16.8/38.8 MB 6.4 MB/s eta 0:00:04\n",
      "     ----------------- ---------------------- 16.8/38.8 MB 6.2 MB/s eta 0:00:04\n",
      "     ----------------- ---------------------- 16.9/38.8 MB 6.1 MB/s eta 0:00:04\n",
      "     ----------------- ---------------------- 17.0/38.8 MB 6.0 MB/s eta 0:00:04\n",
      "     ----------------- ---------------------- 17.1/38.8 MB 5.9 MB/s eta 0:00:04\n",
      "     ----------------- ---------------------- 17.2/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     ----------------- ---------------------- 17.4/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     ------------------ --------------------- 17.5/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     ------------------ --------------------- 17.5/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     ------------------ --------------------- 17.5/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     ------------------- -------------------- 18.7/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     ------------------- -------------------- 18.9/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     ------------------- -------------------- 19.3/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     -------------------- ------------------- 19.6/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     -------------------- ------------------- 19.9/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     -------------------- ------------------- 20.2/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     --------------------- ------------------ 20.5/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     --------------------- ------------------ 20.8/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     --------------------- ------------------ 21.1/38.8 MB 5.8 MB/s eta 0:00:04\n",
      "     ---------------------- ----------------- 21.4/38.8 MB 5.8 MB/s eta 0:00:03\n",
      "     ---------------------- ----------------- 21.7/38.8 MB 5.8 MB/s eta 0:00:03\n",
      "     ---------------------- ----------------- 22.0/38.8 MB 5.8 MB/s eta 0:00:03\n",
      "     ---------------------- ----------------- 22.3/38.8 MB 5.8 MB/s eta 0:00:03\n",
      "     ----------------------- ---------------- 22.5/38.8 MB 5.8 MB/s eta 0:00:03\n",
      "     ----------------------- ---------------- 22.8/38.8 MB 5.8 MB/s eta 0:00:03\n",
      "     ----------------------- ---------------- 23.1/38.8 MB 5.7 MB/s eta 0:00:03\n",
      "     ------------------------ --------------- 23.3/38.8 MB 5.7 MB/s eta 0:00:03\n",
      "     ------------------------ --------------- 23.6/38.8 MB 5.7 MB/s eta 0:00:03\n",
      "     ------------------------ --------------- 23.9/38.8 MB 5.7 MB/s eta 0:00:03\n",
      "     ------------------------ --------------- 24.2/38.8 MB 5.6 MB/s eta 0:00:03\n",
      "     ------------------------- -------------- 24.5/38.8 MB 5.6 MB/s eta 0:00:03\n",
      "     ------------------------- -------------- 24.8/38.8 MB 5.6 MB/s eta 0:00:03\n",
      "     ------------------------- -------------- 25.1/38.8 MB 5.6 MB/s eta 0:00:03\n",
      "     -------------------------- ------------- 25.4/38.8 MB 5.7 MB/s eta 0:00:03\n",
      "     -------------------------- ------------- 25.7/38.8 MB 5.7 MB/s eta 0:00:03\n",
      "     -------------------------- ------------- 26.0/38.8 MB 5.6 MB/s eta 0:00:03\n",
      "     --------------------------- ------------ 26.3/38.8 MB 5.6 MB/s eta 0:00:03\n",
      "     --------------------------- ------------ 26.6/38.8 MB 5.6 MB/s eta 0:00:03\n",
      "     --------------------------- ------------ 26.9/38.8 MB 5.6 MB/s eta 0:00:03\n",
      "     ---------------------------- ----------- 27.2/38.8 MB 6.1 MB/s eta 0:00:02\n",
      "     ---------------------------- ----------- 27.5/38.8 MB 6.3 MB/s eta 0:00:02\n",
      "     ---------------------------- ----------- 27.8/38.8 MB 7.0 MB/s eta 0:00:02\n",
      "     ---------------------------- ----------- 28.0/38.8 MB 6.7 MB/s eta 0:00:02\n",
      "     ----------------------------- ---------- 28.3/38.8 MB 6.5 MB/s eta 0:00:02\n",
      "     ----------------------------- ---------- 28.6/38.8 MB 6.4 MB/s eta 0:00:02\n",
      "     ----------------------------- ---------- 28.9/38.8 MB 6.3 MB/s eta 0:00:02\n",
      "     ------------------------------ --------- 29.3/38.8 MB 6.3 MB/s eta 0:00:02\n",
      "     ------------------------------ --------- 29.5/38.8 MB 6.3 MB/s eta 0:00:02\n",
      "     ------------------------------ --------- 29.9/38.8 MB 6.3 MB/s eta 0:00:02\n",
      "     ------------------------------- -------- 30.2/38.8 MB 6.3 MB/s eta 0:00:02\n",
      "     ------------------------------- -------- 30.5/38.8 MB 6.3 MB/s eta 0:00:02\n",
      "     ------------------------------- -------- 30.8/38.8 MB 6.4 MB/s eta 0:00:02\n",
      "     ------------------------------- -------- 31.1/38.8 MB 6.3 MB/s eta 0:00:02\n",
      "     -------------------------------- ------- 31.4/38.8 MB 6.2 MB/s eta 0:00:02\n",
      "     -------------------------------- ------- 31.7/38.8 MB 6.3 MB/s eta 0:00:02\n",
      "     -------------------------------- ------- 32.0/38.8 MB 6.3 MB/s eta 0:00:02\n",
      "     --------------------------------- ------ 32.3/38.8 MB 6.3 MB/s eta 0:00:02\n",
      "     --------------------------------- ------ 32.6/38.8 MB 6.3 MB/s eta 0:00:01\n",
      "     --------------------------------- ------ 32.9/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------- ----- 33.3/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------- ----- 33.5/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------- ----- 33.9/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ----------------------------------- ---- 34.2/38.8 MB 6.5 MB/s eta 0:00:01\n",
      "     ----------------------------------- ---- 34.5/38.8 MB 6.5 MB/s eta 0:00:01\n",
      "     ----------------------------------- ---- 34.7/38.8 MB 6.5 MB/s eta 0:00:01\n",
      "     ------------------------------------ --- 35.0/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ------------------------------------ --- 35.3/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ------------------------------------ --- 35.7/38.8 MB 6.5 MB/s eta 0:00:01\n",
      "     ------------------------------------- -- 36.0/38.8 MB 6.5 MB/s eta 0:00:01\n",
      "     ------------------------------------- -- 36.2/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ------------------------------------- -- 36.5/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ------------------------------------- -- 36.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     -------------------------------------- - 37.0/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     -------------------------------------- - 37.3/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     -------------------------------------- - 37.6/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     -------------------------------------- - 37.9/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.1/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.5/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.7/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------  38.8/38.8 MB 6.4 MB/s eta 0:00:01\n",
      "     ---------------------------------------- 38.8/38.8 MB 4.6 MB/s eta 0:00:00\n",
      "Requirement already satisfied: numpy>=1.21.2 in d:\\miniconda3\\envs\\ali\\lib\\site-packages (from opencv-python) (1.26.4)\n",
      "Installing collected packages: opencv-python\n",
      "Successfully installed opencv-python-4.10.0.84\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "DEPRECATION: omegaconf 2.0.6 has a non-standard dependency specifier PyYAML>=5.1.*. pip 24.1 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of omegaconf or contact the author to suggest that they release a version with a conforming dependency specifiers. Discussion can be found at https://github.com/pypa/pip/issues/12063\n"
     ]
    }
   ],
   "source": [
    "!pip install opencv-python"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-10-26 10:25:00,213 - modelscope - WARNING - Model revision not specified, use revision: v1.0.0\n",
      "2024-10-26 10:25:00,593 - modelscope - INFO - initiate model from d:\\ComfyUI-aki-v1\\models\\modelscope\\hub\\damo\\cv_unet_universal-matting\n",
      "2024-10-26 10:25:00,595 - modelscope - INFO - initiate model from location d:\\ComfyUI-aki-v1\\models\\modelscope\\hub\\damo\\cv_unet_universal-matting.\n",
      "2024-10-26 10:25:00,601 - modelscope - WARNING - No preprocessor field found in cfg.\n",
      "2024-10-26 10:25:00,602 - modelscope - WARNING - No val key and type key found in preprocessor domain of configuration.json file.\n",
      "2024-10-26 10:25:00,602 - modelscope - WARNING - Cannot find available config to build preprocessor at mode inference, current config: {'model_dir': 'd:\\\\ComfyUI-aki-v1\\\\models\\\\modelscope\\\\hub\\\\damo\\\\cv_unet_universal-matting'}. trying to build by task and model information.\n",
      "2024-10-26 10:25:00,603 - modelscope - WARNING - Find task: universal-matting, model type: None. Insufficient information to build preprocessor, skip building preprocessor\n",
      "2024-10-26 10:25:00,605 - modelscope - INFO - loading model from d:\\ComfyUI-aki-v1\\models\\modelscope\\hub\\damo\\cv_unet_universal-matting\\tf_graph.pb\n",
      "2024-10-26 10:25:01,288 - modelscope - INFO - load model done\n"
     ]
    }
   ],
   "source": [
    "from AliOffline_Seg_Obj import * \n",
    "from alioffline_utils_img import *\n",
    "from PIL import Image\n",
    "\n",
    "img = Image.open('./test/one.jpg')\n",
    "iamges = [pil2tensor(img)]\n",
    "seg = AliOffline_Seg_Obj()\n",
    "#result = seg.sample(iamges,'transparent','transparent')\n",
    "#result = seg.sample(iamges,'blackBK','blackBK')\n",
    "result = seg.sample(iamges,'whiteBK','whiteBK')\n",
    "tensor2pil(result[0][0]).show()\n",
    "tensor2pil(result[1][0]).show()\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "photo",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
